\chapter{序言}

\section{摘要}

很多人已经习惯于使用命令式(imperative)语言，诸如C、C++、Java、Python和Pascal等。对于计算机科学专业的学生来说，Haskell是怪异和愚钝的。这篇教程假设读者熟悉C/C++、Java或Pascal。我之所以写下这篇教程是因为看起来似乎没有其他教程可以帮助学生们克服从C/C++、Java及其他类似的命令式语言转向Haskell所带来的困难。

我写下这篇文章假设你已经了解过the Gentle Introduction Haskell，但仍然不明白是怎么回事。

Haskell不是'有一点不同'，并且不是'仅需要一点时间'。 与之前的命令式语言相比，它是非常的不同，你很难轻易地掌握它，虽然我希望这个教程会有所帮助。

如果你学习Haskell，不要仅仅编写一些玩具程序。简单的问题不能充分利用Haskell的强大功能。只有当你应对艰巨的任务时，它的强大才总能清晰的展现。Haskell的工具将极大简化你的代码。

我将在本教程中设置一些短暂的停顿，因为学习Haskell是很痛苦的，至少对我而言是这样的。我需要休息。并且每当我尝试去理解时，我的大脑就很受伤。

和绝大多数语言相比，Haskell更灵活也更具控制力。虽然我不知道Haskell在控制力方面哪里比C强，但是除非你需要控制内存中的特定字节，否则的话Haskell拥有了所有C所拥有的控制力。所以我称Haskell为一门强大的语言，而不仅仅是一门'好'语言。

我之所以写下这篇教程是因为对我来说Haskell很难学，但是现在我喜欢上它了。“Haskell太难了” “你无法按照已知的方式编写代码” “大脑很受伤” “没有好的参考资料” 这些都是我在上大学时所说的。现在有很多很好的参考资料，但是它们都没有覆盖实际问题：因为程序员都懂C。

这个摘要是由Mark Evans，\href{http://lambda-the-ultimate.org/node/view/724}{这里}，根据我的作品整理而成的。我与Mark Evans没有联系，但这是因为他根据我的作品整理这个摘要并将它发布在lambda-the-ultimate上时也没有联系我。我怀疑他不会在乎我将这篇文章作为本书摘要。如果他愿意，他可以与我联系谈谈关于这份摘要的合法地位的事宜。目前，我假设我仍然拥有这本书的版权，包括这篇摘要（阅读下面关于许可的小节）。

\section{下载}
To补充。

\section{许可}

我觉定我应该详细说明一下关于此教程的许可问题。总之，只要在这个教程上保留我的署名，你可以做任何你想做的事情，包括修改、重新发布或出售衍生作品。\textbf{特别是，你可以将它用于在商业背景下的教学活动中，诸如内部培训或咨询。}我很欢迎听到某个公司使用本教程来给员工做Haskell培训。所以请随意使用。任何衍生作品也需携带此许可，顺便说一下。 “同样分享”。谢谢，创作共用(Creative Commons)。该链接指向其法律措辞。

本著作在\href{http://creativecommons.org/licenses/by-sa/2.5/}{Creative Commons Attribution-ShareAlike 2.5 License}许可下。

\section{本教程的目的和其他在线参考}
Many people are accustomed to imperative languagues, which include C, C++, Java, Python, and Pascal. In fact most languages in common usage are imperative, other than LISP, Scheme, ML, or OCaml. For computer science students, it is virtually guaranteed that Haskell is weird and obtuse. I first encountered Haskell in the classroom when I was a freshman at UT Austin, and then in another class two years later. I was only familiar with C/C++, Pascal, and QBASIC, and all of the Haskell tutorials and books seemed to assume more of my education. This tutorial assumes that the reader is familiar with C/C++, Python, Java, or Pascal. Specifically, this tutorial is for \textbf{students} of computer science, people in their first few years of college, or even in high school. I am writing for you because it seems that no other tutorial was written to help students overcome the difficulty of moving from C/C++, Java, and the like to Haskell.

I write this assuming that you have checked out the following tutorial, the Gentle Introduction to Haskell, but found that you still don't understand what's going on:

\textit{\href{http://www.haskell.org/tutorial/}{http://www.haskell.org/tutorial/}}

That tutorial is a good reference for basic syntax. In this tutorial we will skip most of that until later when it is clear why function definition is so important in Haskell. Here is another tutorial, the Tour of the Haskell Syntax, with much more specific information:

\textit{\href{http://www.cs.uu.nl/~afie/haskell/tourofsyntax.html}{http://www.cs.uu.nl/~afie/haskell/tourofsyntax.html}}

Refer to it, too. It has the appropriate syntax for most of the things I discuss, without requiring you to know Haskell's depths. Please read both of these after, during, or even before reading this tutorial.

One of the best references is the source code for the Prelude, the file "Prelude.hs", where all of the general-purpose functions are defined. You can find it in Hugs's install directories someplace. If any function shows up that you don't understand, you can look up its definition and figure out what it's really doing. This is a very good practice for those unfamiliar with general Haskell use.

Another resource is the GHC Hierarchical Libraries documentation. These have the types and module names for everything in GHC, and most of the time have meaningful commentary:

\textit{\href{http://www.haskell.org/ghc/docs/latest/html/libraries/index.html}{http://www.haskell.org/ghc/docs/latest/html/libraries/index.html}}

There is also a newer version of that documentation for the 'newAPI' in the most recent CVS version of GHC. Since writing the first draft of this tutorial, HOpenGL moved to the main version, so this link is not necessary for finding HOpenGL documentation. However, I still include it because some of GHC's newest extensions, such as HOpenAL (note the 'AL') are here, as of 7/3/05:

\textit{\href{http://www.haskell.org/HOpenGL/newAPI/}{http://www.haskell.org/HOpenGL/newAPI/}}

Finally, if you don't already have them, get and install both Hugs and GHC. Hugs will let you play around and learn, and GHC will be necessary for your more advanced tasks later on. GHCi (GHC interactive) comes with GHC, and is a close substitute for Hugs. It is a little harder (I think) to play around with. It may be equal in utility now, so check it out, too. If you use Debian, Hugs and GHC are packages. For everyone else, the homepages are here:

\textit{\href{http://www.haskell.org/hugs/}{http://www.haskell.org/hugs/}}
\textit{\href{http://www.haskell.org/ghc/}{http://www.haskell.org/ghc/}}

\section{与我们的其他教程的关系}

You may be here because you're trying to use HOpenGL. The tutorial you're reading was written along with our other tutorial on rendering and texture examples in HOpenGL, and if you are familiar with Haskell you can go directly there:

\href{http://www.kt.rim.or.jp/~kbk/HOpenGL/HOpenGL.html}{Dave Morra's HOpenGL tutorial}

Otherwise, read this tutorial and those mentioned above first, then check out our HOpenGL tutorial if you like. If we've written well enough you should be able to not only use Haskell but HOpenGL as well. On with the tutorial.

\section{序和风格说明}

I am not writing a Haskell reference. This is a tutorial designed to take someone having trouble understanding Haskell and help them. This tutorial is for people who, like me, needed to learn enough concepts to understand the code covered in a classroom. Haskell allows things to be done easily and clearly, but it is not easy or clear, and it can be extremely challenging for a novice. You cannot pick up Haskell code and understand it. What I have attempted to write is a tutorial that covers the common aspects of Haskell that are the most obtuse.

As the tutorial progresses, one thing should become clear about Haskell: its real power comes into play when you attack difficult problems. Because of this, I use some difficult problems in this tutorial. Don't worry if you don't understand the solutions after reading the tutorial once. Haskell is not a toy language, and even a moderately sized set of functions will include several of Haskell's complicated tools all working together. This has left educators with a dilemma: do I use ridiculously simple code in order to cover a single topic at once, or do I use something actually useful and try to explain all the pieces and how they all fit together? Many tutorials and lessons have chosen the former, but I prefer the latter. That means that each example requires a lot of explaining. Often concepts must be explained once in extremely simplistic terms, and then explained again later after other related topics have also been briefly discussed. As you read this tutorial, remember this: Haskell's real power is the fact that all of its pieces fit so well together, not just that they are good pieces.



